package com.ericom.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
public class Poll extends BaseObject {

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id)
				.append("pollDate", pollDate).append("polledBy", polledBy)
				.toString();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof Poll))
			return false;
		Poll castOther = (Poll) other;
		return new EqualsBuilder().append(id, castOther.id)
				.append(pollDate, castOther.pollDate)
				.append(polledBy, castOther.polledBy).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(id).append(pollDate)
				.append(polledBy).toHashCode();
	}

	private Long id;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "poll_date")
	public String getPollDate() {
		return pollDate;
	}

	public void setPollDate(String pollDate) {
		this.pollDate = pollDate;
	}

	@Column(name = "polled_by")
	public String getPolledBy() {
		return polledBy;
	}

	public void setPolledBy(String polledBy) {
		this.polledBy = polledBy;
	}
	@ManyToOne(cascade={CascadeType.REFRESH})
	@JoinColumn(name="vote_id")
	public Vote getVote() {
		return vote;
	}

	public void setVote(Vote vote) {
		this.vote = vote;
	}

	private String pollDate;
	private String polledBy;
	private Vote vote;
}
